package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.SerOrderInfo;
import com.yiya.bean.SysUser;
import com.yiya.mapper.SerOrderInfoMapper;
import com.yiya.model.SerOrderInfoCplex;
import com.yiya.model.SerOrderInfoCplexModel;

@Service("serOrderInfoService")
public class SerOrderInfoService{
	@Autowired
	private SerOrderInfoMapper serOrderInfoMapper;

	public List<SerOrderInfoCplex> queryByList(SerOrderInfoCplexModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<SerOrderInfoCplex> list = serOrderInfoMapper.selectByModel(bean);
		return list;
	}

	public int queryByCount(SerOrderInfoCplexModel bean) {
		return serOrderInfoMapper.countByModel(bean);
	}
	
	public int add(SerOrderInfo bean){
		return serOrderInfoMapper.insert(bean);
	}
	
	public int Update(SerOrderInfo bean){
		return serOrderInfoMapper.updateByPrimaryKeySelective(bean);
	}
	
	public SerOrderInfo queryById(Integer id){
		return serOrderInfoMapper.selectByPrimaryKey(id);
	}
	
	public void delete(Integer[] ids,SysUser user){
		for(Integer id:ids){
			Date nowTime = new Date();
			SerOrderInfo bean = serOrderInfoMapper.selectByPrimaryKey(id);
			bean.setUpdateBy(user.getId());
			bean.setUpdateTime(nowTime);
			bean.setDelFlag(1);
			serOrderInfoMapper.updateByPrimaryKeySelective(bean);
		}
	}
	
	public int getUnfinishedOrderCount(int userId){
		SerOrderInfoCplexModel model = new SerOrderInfoCplexModel();
		model.setCreateBy(userId);
		return serOrderInfoMapper.selectUnfinishedOrderCount(model);
	}
	
}
